package com.stox.ui.javafx.charting.model.uiunit;

import java.util.List;

import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;

import com.stox.ui.javafx.charting.model.plot.AbstractPrimaryPlot;
import com.stox.ui.javafx.charting.widget.PrimaryChart;

public abstract class AbstractPrimaryUiUnit<T, 
			W extends PrimaryChart<U>,
			V extends AbstractPrimaryUiUnit<T,W, V, U>, 
			U extends AbstractPrimaryPlot<T,W,V,U>> 
	extends AbstractUiUnit<T,W,V, U> {

	private Color backgroundColor;
	
	public AbstractPrimaryUiUnit(T model, U plot, int index) {
		super(model, plot, index);
	}
	
	public void updateWidth(double volume) {
		width = getPlot().getChart().getCanvas().getWidth();
		width = getPlot().getChart().isEquivolume() ?
				width*volume/getPlot().getVolumeSum() :
				width/(getPlot().getChart().getChartingView().getEndIndex() - 
						getPlot().getChart().getChartingView().getStartIndex());
	}

	public void paintBackground() {
		Canvas canvas = getPlot().getChart().getCanvas();
		GraphicsContext gc = canvas.getGraphicsContext2D();
		gc.setFill(backgroundColor);
		gc.fillRect(x, canvas.getLayoutY(), x+width, canvas.getLayoutY()+canvas.getHeight());
	}

	public abstract List<String> info();
	
	public Color getBackgroundColor() {
		return backgroundColor;
	}


	public void setBackgroundColor(Color backgroundColor) {
		this.backgroundColor = backgroundColor;
	}

}
